package com.example.busshop.service;

import com.example.busshop.common.service.LogicService;
import com.example.busshop.config.R;
import com.example.busshop.dao.ItemDao;
import com.example.busshop.dao.OrderDao;
import com.example.busshop.dao.ShopDao;
import com.example.busshop.dao.ShopItemDao;
import com.example.busshop.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

@Service
public class ShopService extends LogicService<ShopDao,Shop,Long> {
    public ShopService(@Autowired ShopDao dao) {
        super(dao);
    }
    @Resource
    ShopItemDao shopItemDao;
    @Resource
    OrderDao orderDao;
//    @Resource
//    ItemDao itemDao;
    public Item addItem(Item item,Long shopId){
       Shop shop=getDAO().getReferenceById(shopId);
       Item item1=shop.addItem(item);
       getDAO().save(shop);
       return item1;
    }
    public ShopItem newItem(Long shopId,Item item){
        Shop shop=getDAO().getReferenceById(shopId);
        ShopItem shopItem=shop.newItem(item);
        getDAO().save(shop);
        return shopItem;
    }
    public Set<Order> listAll(Long shopId){
        Shop shop=getDAO().getReferenceById(shopId);
        return shop.getOrders();
    }
    public R QueRen(Long oid){
        Order order=orderDao.getReferenceById(oid);
        order.setStatus(2);
        orderDao.save(order);
        return R.ok().message("已确认");
    }
    public R Refund(Long oid){
        Order order=orderDao.getReferenceById(oid);
        order.setStatus(3);
        orderDao.save(order);
        return R.ok().message("已退款");
    }
    public Set<Order> allOrder(Long sId){
//        Shop shop=getDAO().getReferenceById(sId);
        return orderDao.listOrderBus(sId);
    }
    public Set<ShopItem> allItems(Long sId){
        Shop shop=getDAO().getReferenceById(sId);
        return shop.getShopItems();
    }
//    public Set<ShopItem> allItem(Long sId){
//        return shopItemDao.All(sId);
//    }
//    public Set<Item> all() {
//        return itemDao.allItem();
//    }
}
